import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import postcssPxToViewport from "postcss-px-to-viewport";
import path from "path";

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react()],
  // 配置适配
  css: {
    postcss: {
      plugins: [
        postcssPxToViewport({
          unitToConvert: "px",
          viewportWidth: 375,
          unitPrecision: 5,
          propList: ["*"],
          viewportUnit: "vw",
          fontViewportUnit: "vw",
          selectorBlackList: [],
          minPixelValue: 1,
          mediaQuery: false,
          replace: true,
          exclude: [],
          landscape: false,
          landscapeUnit: "vw",
          landscapeWidth: 568,
        }),
      ],
    },
  },
  // 配置别名
  resolve: {
    alias: { "@": path.resolve(__dirname, "./src") },
  },
  // 配置跨域
  server: {
    proxy: {
      "^/api": {
        target: "https://52coding.cc/yuantiku_api/",
        changeOrigin: true,
        rewrite: (url) => url.replace(/^\/api/, ""),
      },
    },
  },
});
